package com.ruoyi.web.controller.starbucks;

import java.util.List;

import com.ruoyi.starbucks.domain.QueryStarbucksRewards;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.starbucks.domain.StarbucksRewards;
import com.ruoyi.starbucks.service.IStarbucksRewardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠券Controller
 *
 * @author ruoyi
 * @date 2021-01-08
 */
@RestController
@RequestMapping("/starbucks/rewards")
public class StarbucksRewardsController extends BaseController
{
    @Autowired
    private IStarbucksRewardsService starbucksRewardsService;

    /**
     * 查询优惠券列表
     */
    @ApiOperation("查询优惠券列表")
    @PreAuthorize("@ss.hasPermi('starbucks:rewards:list')")
    @GetMapping("/list")
    public TableDataInfo list(QueryStarbucksRewards starbucksRewards)
    {
        startPage();
        List<StarbucksRewards> list = starbucksRewardsService.selectStarbucksRewardsList(starbucksRewards);
        return getDataTable(list);
    }

    /**
     * 导出优惠券列表
     */
    @PreAuthorize("@ss.hasPermi('starbucks:rewards:export')")
    @Log(title = "优惠券", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QueryStarbucksRewards starbucksRewards)
    {
        List<StarbucksRewards> list = starbucksRewardsService.selectStarbucksRewardsList(starbucksRewards);
        ExcelUtil<StarbucksRewards> util = new ExcelUtil<StarbucksRewards>(StarbucksRewards.class);
        return util.exportExcel(list, "rewards");
    }

    /**
     * 获取优惠券详细信息
     */
    @ApiOperation("获取优惠券详细信息")
    @PreAuthorize("@ss.hasPermi('starbucks:rewards:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(starbucksRewardsService.selectStarbucksRewardsById(id));
    }

    /**
     * 新增优惠券
     */
    @PreAuthorize("@ss.hasPermi('starbucks:rewards:add')")
    @Log(title = "优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StarbucksRewards starbucksRewards)
    {
        return toAjax(starbucksRewardsService.insertStarbucksRewards(starbucksRewards));
    }

    /**
     * 修改优惠券
     */
    @PreAuthorize("@ss.hasPermi('starbucks:rewards:edit')")
    @Log(title = "优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StarbucksRewards starbucksRewards)
    {
        return toAjax(starbucksRewardsService.updateStarbucksRewards(starbucksRewards));
    }

    /**
     * 删除优惠券
     */
    @PreAuthorize("@ss.hasPermi('starbucks:rewards:remove')")
    @Log(title = "优惠券", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(starbucksRewardsService.deleteStarbucksRewardsByIds(ids));
    }

    /**
     * 获取可用优惠券类型
     */
    @ApiOperation("获取可用优惠券类型")
    @GetMapping("queryRewardsType")
    public AjaxResult queryRewardsType(){
        return starbucksRewardsService.queryRewardsType();
    }

}